class Text:
    __doc__=""" 
A class to hold text chunk objects
    
Fields:
    text - the actual text
    bold, italic, underline, superscript, subscript - text boolean attributes
    font - font face
    size - font size
    color - font color (in hex)
           
Constants:
    None yet.

Methods:
    __init__(text) - constructor, accepts 0-1 paramaters
    copy_style(other) - copies all non-text attributes from another chunk
    set_attrib(attrib, value) - sets an atribute with a value (where applicable)
    self_print() - prints chunk data on the console
    
Future improvements:
    Possibly, a method which returns a PyGTK paintable object.
    If it were Java, it would have proabably been called paint(Graphics g)
""" 
    #Default constructor
    def __init__(self,text='',bold=False,italic=False,underline=False,subscript=False,superscript=False,font=None,size=10,color='black'):
        self.text=text
        self.bold=bold
        self.italic=italic
        self.underline=underline
        self.subscript=subscript
        self.superscript=superscript
        self.font=font
        self.size=size
        self.color=color
        
    #Copies the stile (all fields except text) from the "other" text
    def copy_style(self,other):
        self.bold=other.bold
        self.italic=other.italic
        self.underline=other.underline
        self.subscript=other.subscript
        self.superscript=other.superscript
        self.font=other.font
        self.size=other.size
        self.color=other.color
    
    #Sets the atribute to a given value, if applicable
    def set_attrib(self,attrib,value=""):
        if attrib=='text':
            self.text=value
        elif attrib=='b':
            self.bold=True
        elif attrib=='i':
            self.italic=True
        elif attrib=='u':
            self.underline=True
        elif attrib=='sup':
            self.superscript=True
        elif attrib=='sub':
            self.subscript=True
        elif attrib=='font':
            self.font=value
        elif attrib=='size':
            self.size = int(value)
        elif attrib=='h1':
            self.size+=6
        elif attrib=='h2':
            self.size+=4
        elif attrib=='h3':
            self.size+=2
        elif attrib=='color':
            self.color=value
        else:
            pass
        
    #Prints the important data on the console
    def self_print(self):
        print '[',self.text,'(',
        if self.bold:
            print 'b,',
        if self.italic:
            print 'i,',
        if self.underline:
            print 'u,',
        if self.subscript:
            print 'sub,',
        if self.superscript:
            print 'sup,',
        print self.font,self.size,self.color,')]'
        
